<?php 
	//获得参数
	$echostr = $_GET['echostr'];
    $signature = $_GET['signature'];
    $timestamp = $_GET['timestamp'];
    $nonce = $_GET['nonce'];
    $token = 'XX';
    //形成数组，按字典进行排序
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr, SORT_STRING); 
    //拼接字符串，进行加密
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );
    //对比，返回结果
    if( $tmpStr == $signature && $echostr){
	    //第一次验证
	    echo $echostr;
	    die;
	}else{
	    //非第一次，实现其他功能
	    $this -> xx();
	    }



	public function get_access_token(){
	    //开发者的appid和appsecret
	    $appid = 'xxxxx';
	    $appsecret = 'xxxxxxxxx';
	    //access_token获取地址：
	    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
	   
	    //1.实例化（初始化curl）  
	    $curl = curl_init();
	    //2.设置curl参数
	    curl_setopt($curl, CURLOPT_URL, $url);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
	    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在  
	    //3. 数据采集
	    $res= curl_exec($curl);
	    //4. 关闭
	    curl_close($curl);
	   
	   
	    $arr = json_decode($res,true);
		//得到的access_token
		//当前token获取时间
	    $access_token_time = time();
	    //access_token和token_time存到session中
	    session('access_token',$arr['access_token']);
	    session('access_token_time',$access_token_time);
  
    } 


 ?>